home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: How to tell if a file exists in C
- Date: Sat, 17 Feb 96 19:51:44 GMT
- Organization: none
- Message-ID: <824586704snz@genesis.demon.co.uk>
- References: <823685019.AA00170@escan.demon.co.uk> <4g3dh7$co6@linet06.li.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4g3dh7$co6@linet06.li.net> sbda@newshost.li.net "sbda" writes:
-
- >Here's another way - it's ANSI C - so it should work on all C compilers
- >and on all OSes:
- >
- >/*---------------------------------------*/
- >FILE *fp;
- >
- > fp = fopen("filename.ext", "r");
- >
- > if (fp == NULL) puts("File not found");
- >/*---------------------------------------*/
- >
- > If the filespec doesn't exist, fp will be set to NULL. If it does
- >exist, then fp will contain a non-NULL (non-zero) value.
-
- That of course tests whether a file exists and is readable. A file that
- exists but is, say, only writable would fail that test.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-